<?php
namespace Home\Controller;
use Think\Controller;
class ApplyController extends Controller {
	
	 public function _initialize(){
        //检测登陆
        if (!isset($_SESSION['username']) || $_SESSION['username'] == '') {
            $this->redirect('Home/Login/index');
        }
	 }
    
    public function index(){
    	$sliders = M('Slider')->where(array('status'=>1))->select();
    	$this->assign('sliders',$sliders);

    	$article = M('Article');
    	$categoryArr = getCategory();	
    	$notifications = $article->where(array('category_id' => $categoryArr['notificationId'] ))->limit(5)->select();
    	$this->assign('notifications',$notifications);

    	$competitions = $article->where(array('category_id'=> $categoryArr['competitionId']))->limit(5)->select();
    	$this->assign('competition1',$competitions[0]);
    	unset($competitions[0]);
    	$this->assign('competitions',$competitions);

 		$this->display('apply');       
    }
	
	public function apply(){
		$teamData = I('post.');
		//echo '<pre />';
		//print_r($teamData);
		$model = D('Apply');
		if($model->create($teamData) == false){
			$errMsg = $model->getError();
			$this->error('报名失败：' . $errMsg);
		}
		
		if($model->add() == false){
			$errMsg = $model->getError();
			$this->error('报名失败：' . $errMsg);
		}
		$this->success('报名成功！', U("Home/Apply/index"), 1);
	}
    
}












